#include "ExplosionMush.h"
#include "OgreStringConverter.h"
#include "OgreMath.h"

ExplosionMush::ExplosionMush(Ogre::SceneManager * sceneManager):AnimationEvent() {
	systemNameExplosion = 0;
	_mScene = sceneManager;
	_started = false;
}

ExplosionMush::~ExplosionMush(void) {}

void ExplosionMush::prepareEvent() {
	_explosionParticleSystem = _mScene->createParticleSystem("ExplosionMush" + Ogre::StringConverter::toString(systemNameExplosion), "Explosion_mush");
	systemNameExplosion++;
	_explosionNode = _mScene->createSceneNode();
	_explosionNode->translate(0,1000,0,Ogre::Node::TS_PARENT);
	_explosionNode->attachObject(_explosionParticleSystem);

	_explosionParticleSystem->setRenderQueueGroup(Ogre::RENDER_QUEUE_7);
}

void ExplosionMush::startEvent() {
	_mScene->getRootSceneNode()->createChildSceneNode()->addChild(_explosionNode);
	_started = true;
}

void ExplosionMush::restartEvent() {
	this->prepareEvent();
	this->startEvent();
}

bool ExplosionMush::hasStarted() {
	return _started;
}

void ExplosionMush::update(float deltatime) {
	
	float y = _explosionNode->getPosition().y;

	if(_explosionNode->getPosition().y < 1300) {
		_explosionNode->setPosition(0,y+deltatime*2.5,0);
		_explosionNode->setPosition(0,y+deltatime*2.0,0);
	}

	else if(_explosionNode->getPosition().y < 2000) {
		_explosionNode->setPosition(0,y+deltatime*1.5,0);
	}
}

void ExplosionMush::quit() {
	_explosionParticleSystem->removeAllEmitters();
	_started = false;
}

